package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.TAuditVo;
import com.ruoyi.system.domain.bo.TAuditBo;
import com.ruoyi.system.service.ITAuditService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审核表
 *
 * @author ruoyi
 * @date 2024-03-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/audit")
public class TAuditController extends BaseController {

    private final ITAuditService iTAuditService;

    /**
     * 查询审核表列表
     */
    @SaCheckPermission("system:audit:list")
    @GetMapping("/list")
    public TableDataInfo<TAuditVo> list(TAuditBo bo, PageQuery pageQuery) {
        return iTAuditService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出审核表列表
     */
    @SaCheckPermission("system:audit:export")
    @Log(title = "审核表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TAuditBo bo, HttpServletResponse response) {
        List<TAuditVo> list = iTAuditService.queryList(bo);
        ExcelUtil.exportExcel(list, "审核表", TAuditVo.class, response);
    }

    /**
     * 获取审核表详细信息
     *
     * @param pkid 主键
     */
    @SaCheckPermission("system:audit:query")
    @GetMapping("/{pkid}")
    public R<TAuditVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String pkid) {
        return R.ok(iTAuditService.queryById(pkid));
    }

    /**
     * 新增审核表
     */
    @Log(title = "审核表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TAuditBo bo) {
        return toAjax(iTAuditService.insertByBo(bo));
    }

    /**
     * 修改审核表
     */
    @SaCheckPermission("system:audit:edit")
    @Log(title = "审核表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TAuditBo bo) {
        return toAjax(iTAuditService.updateByBo(bo));
    }

    /**
     * 删除审核表
     *
     * @param pkids 主键串
     */
    @SaCheckPermission("system:audit:remove")
    @Log(title = "审核表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pkids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] pkids) {
        return toAjax(iTAuditService.deleteWithValidByIds(Arrays.asList(pkids), true));
    }
}
